<?php
/**
 * vgoshop
 * ============================================================================
 * 网站地址: http://www.vgo.me
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author: myhonour
 * DateTime: 2017/10/9 下午6:40
 */

namespace app\index\controller;


use app\admin\model\Column;

class Show extends Common
{

    public function lists($name,$data = 'show'){
            ($column =  Column::get(['alias' =>  $name],'model')) OR ($column->type == Column::LINKS_TYPE) OR $this->error('error 404');
            // 面包屑
            $this->assign('parents',Column::init()->crumbs($column->column_id));
            if ($column->model_id == Column::SINGLE_PAGE){
                // 单页模型
                $this->assign('contents',htmlspecialchars_decode($column->content));
                $this->assign('title',$column->name);
                $this->assign('img',$column->catpic);
                $this->assign('info',$column->description);
                return $this->fetch('contents/'.clearSuffix(($column->content_template?:'single_page')));
            }
            // 查子栏目
            $childColumn = Column::init()->classAChild($column->column_id);
            $this->assign('childColumn',$childColumn);
            // 根据 所有子栏目id  查 属于这些栏目的 内容  有可能 此栏目的 子栏目 不为同一个模型 可能是 多个模型
            $default    =   'default_lists';
            if ($data == 'show'){
                $this->assign('contents',Column::init()->showColumnsLevel($column));
            }elseif ($data == 'showdata'){
                $this->assign('contents',Column::init()->showColumnOfContent($childColumn));
                $default    =   'default_lists_show';
            }else{
                $this->error('error 404');
            }
            $default    =   $column->list_template?clearSuffix($column->list_template):$default;
            $this->assign('column',$column);
            return $this->fetch('lists/'.$default);
    }

    public function contents($name,$item){
        ($column =  Column::get(['alias' =>  $name],'model')) OR ($column->type == Column::LINKS_TYPE) OR ($column->model_id == Column::SINGLE_PAGE) OR $this->error('error 404');
        $class = '\app\admin\model\\'.ucwords($column->model->tablename);
        ($content    =   $class::get(['status' => 1,'recycle' => 0,$column->model->tablename.'_id' => $item])) OR $this->error('无数据！');
        $content->click+=1;
        $content->save();
        $default = $column->content_template?clearSuffix($column->content_template):'default_contents';
        $this->assign('column',$column);
        $this->assign('parents',Column::init()->crumbs($column->column_id));
        $this->assign('contents',$content);
        return $this->fetch('contents/'.$default);
    }
}